package main

import (
	"bytes"
	"encoding/json"
	"io"
	"log"
	"net/http"
	"rss/config"
)

func send2Gotify(title string, message string, priority int8, extra map[string]interface{}) string {
	data := map[string]interface{}{
		"extras":   extra,
		"message":  message,
		"priority": priority,
		"title":    title,
	}
	payload, err := json.Marshal(data)
	response, err := http.Post(config.Conf.Gotify.Url+"/message?token="+config.Conf.Gotify.Token, "application/json", bytes.NewBuffer(payload))
	if err != nil {
		log.Printf("gotify发送失败: %v\n", err)
		return ""
	}
	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {
		}
	}(response.Body)
	body, _ := io.ReadAll(response.Body)
	return string(body)
}
